#!/bin/bash

dirs=$(ls ./)
message="Already up-to-date."
#echo $dirs

for dir in $dirs
do
    cd $dir
    res=$(git pull)
    if test "${res}" = "${message}"
      then
        cd ..
        continue
    fi
    if [ ! -d /var/www/web/$dir ];then
      mkdir -p /var/www/web/$dir
    fi
    if [ -d dist ];then
      sudo cp -rf  dist/* /var/www/web/$dir
    fi
    if [ -d www ];then
      sudo cp -rf  www/* /var/www/web/$dir
    fi
    cd ..
    echo "$(date) ${dir}" > .project-pull.log
done